package pri.zxx.word.util;

import pri.zxx.word.dat.AbstractWordData;

import java.lang.reflect.Field;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class WordUtil {

    public static Set<String> pares(String text) {
        Pattern r = Pattern.compile("\\{([^}])*\\}");
        // 现在创建 matcher 对象
        Matcher m = r.matcher(text);
        //获取括号里面的内容
        Set<String> matchList = new HashSet<>();
        while (m.find()) {
            matchList.add(m.group());
        }
        return matchList;
    }

    public static <T extends AbstractWordData> Map<String, Field> fieldMap(T aClass) {
        Field[] declaredFields = aClass.getClass().getDeclaredFields();
        Map<String, Field> collect = Arrays.stream(declaredFields).collect(Collectors.toMap(o -> "{" + o.getName() + "}", o -> o, (o1, o2) -> o2));
        return collect;
    }
}
